import { ref } from 'vue'
import { adapter, request } from '@/request'
import { promotionAllCreativeByGet } from '@/core/api/promotion'
import type { RequestWrapper } from '@/core/interfaces/common'
import type { PlatformEnum } from '@/core/enums/platform'

export interface AllCreative {
  // 易百搜创意id
  id: number
  // 产品id
  productId: number
  // 百度pc投放计划id
  pcCampaignId: number
  // 百度wap投放计划id
  wapCampaignId: number
  orderId: number
  orderWordId: number
  serviceUserName?: string
  // 百度投放计划id
  campaignId: number
  // 百度单元id
  groupId: number
  // 关键词id
  keywordId: number
  // 百度创意id
  creativeId: number
  word: null
  comboName?: string
  clientType: PlatformEnum
  type: number
  destinationUrl?: string
  // pc带参数的落地页
  pcUrlParams?: string
  // wap带参数的落地页
  wapUrlParams?: string
  title: string
  content: string
  description1?: string
  description2?: string
  serviceApproveStatus: number
  serviceStatus: number
  // 关键词百度审核状态
  wordApproveStatus: number
  // 关键词投放状态
  wordStatus: number
  // 单元百度审核状态
  groupApproveStatus: number
  // 单元投放装态
  groupStatus: number
  // 创意的创建用户id
  createUserId: number
  createTime: string
  // 创意的更新用户id
  updateUserId: number
  updateTime: string
  // 创意审核通过时间
  creativeApproveTime?: string
}

export const allCreativeCols = [
  {
    title: '易百搜创意id',
    key: 'id'
  },
  {
    title: '客户信息',
    key: 'customerName'
  },
  {
    title: '百度pc投放计划id',
    key: 'pcCampaignId'
  },
  {
    title: '百度wap投放计划id',
    key: 'wapCampaignId'
  },
  {
    title: '订单id',
    key: 'orderId'
  },
  {
    title: '订单关键词id',
    key: 'orderWordId'
  },
  {
    title: '投放账号',
    key: 'serviceUserName'
  },
  {
    title: '百度投放计划id',
    key: 'campaignId'
  },
  {
    title: '百度单元id',
    key: 'groupId'
  },
  {
    title: '关键词id',
    key: 'keywordId'
  },
  {
    title: '百度创意id',
    key: 'creativeId'
  },
  {
    title: '关键词',
    key: 'word'
  },
  {
    title: '购买套餐',
    key: 'comboName'
  },
  {
    title: '端口',
    key: 'clientType'
  },
  {
    title: '',
    key: 'type'
  },
  {
    title: '落地页',
    key: 'destinationUrl'
  },
  {
    title: 'pc带参数的落地页',
    key: 'pcUrlParams'
  },
  {
    title: 'wap带参数的落地页',
    key: 'wapUrlParams'
  },
  {
    title: '标题',
    key: 'title'
  },
  {
    title: '内容',
    key: 'content'
  },
  {
    title: '内容1',
    key: 'description1'
  },
  {
    title: '内容2',
    key: 'description2'
  },
  {
    title: '审核状态',
    key: 'serviceApproveStatus'
  },
  {
    title: '上线状态',
    key: 'serviceStatus'
  },
  {
    title: '关键词百度审核状态',
    key: 'wordApproveStatus'
  },
  {
    title: '关键词投放状态',
    key: 'wordStatus'
  },
  {
    title: '单元百度审核状态',
    key: 'groupApproveStatus'
  },
  {
    title: '单元投放装态',
    key: 'groupStatus'
  },
  {
    title: '创意的创建用户id',
    key: 'createUserId'
  },
  {
    title: '创建时间',
    key: 'createTime'
  },
  {
    title: '创意的更新用户id',
    key: 'updateUserId'
  },
  {
    title: '更新时间',
    key: 'updateTime'
  },
  {
    title: '创意审核通过时间',
    key: 'creativeApproveTime'
  }
]

export function getPromotionAllCreative() {
  const service = adapter<RequestWrapper<AllCreative[]>>(request)
  const loading = ref(false)

  const fetch = () => {
    const { url, method } = promotionAllCreativeByGet()
    loading.value = true

    return service({
      config: {
        url,
        method
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [null, fetch, loading] as const
}
